package io.gitee.welson.sensitive.strategy.impl;

import io.gitee.welson.sensitive.annotation.SensitiveStrategyComponent;
import io.gitee.welson.sensitive.strategy.SensitiveStrategy;
import io.gitee.welson.sensitive.util.SensitiveUtil;

/**
 * 身份证号脱敏策略
 * 规则：保留前6位和后4位，中间用*代替
 *
 * @author welson
 */
@SensitiveStrategyComponent
public class IdCardSensitiveStrategy implements SensitiveStrategy {

    private static final int MIN_LENGTH = 15;
    private static final int KEEP_PREFIX = 6;
    private static final int KEEP_SUFFIX = 4;

    @Override
    public String desensitize(String value, String... params) {
        if (SensitiveUtil.isInvalid(value, MIN_LENGTH)) {
            return value;
        }
        return SensitiveUtil.mask(value, KEEP_PREFIX, KEEP_SUFFIX);
    }
} 